package com.gitee.neuray.security.par.scoreManage.controller;

import com.gitee.neuray.security.common.constant.CommonConstants;
import com.gitee.neuray.security.common.msg.ObjectRestResponse;
import com.gitee.neuray.security.common.msg.TableResultResponse;
import com.gitee.neuray.security.common.util.Query;
import com.gitee.neuray.security.common.util.UUIDUtils;
import com.gitee.neuray.security.par.ParExamPlan.biz.ParExamPlanBiz;
import com.gitee.neuray.security.par.ParExamPlan.entity.ParExamPlanEntity;
import com.gitee.neuray.security.par.scoreManage.entity.ParExamCateVO;
import com.gitee.neuray.security.par.scoreManage.entity.ParExamInfoEntity;
import com.gitee.neuray.security.par.scoreManage.biz.ParExamInfoBiz;
import com.gitee.neuray.security.par.scoreManage.entity.ParExamInfoVO;
import com.gitee.neuray.security.par.scoreManage.entity.ParExamScoreEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.gitee.neuray.security.common.rest.BaseController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * 考评表
 *
 * @author dev
 * @email ${email}
 * @date 2020-08-27 09:39:50
 */
@RestController
@RequestMapping("/scoreManage")
public class ParExamInfoController extends BaseController<ParExamInfoBiz, ParExamInfoEntity>{

    @Autowired
    private ParExamInfoBiz parExamInfoBiz;

    @Autowired
    private ParExamPlanBiz parExamPlanBiz;

    @RequestMapping(value = "/listPage", method = RequestMethod.GET)
    public TableResultResponse<ParExamInfoVO> listPage(@RequestParam Map<String, Object> params){
        params.put("crtUser",String.valueOf(request.getHeader(CommonConstants.WEB_USERID)));
//        params.put("orgCode",String.valueOf(request.getHeader("orgCode")));
        Query query = new Query(params);
        return parExamInfoBiz.page(query);
    }

    @RequestMapping(value = "/getPlan" ,method = RequestMethod.GET)
    public List<ParExamPlanEntity> getPlan(@RequestParam Map<String, Object> params){
        ParExamPlanEntity parExamPlanEntity = new ParExamPlanEntity();
        parExamPlanEntity.setScbj(params.get("scbj").toString());
        parExamPlanEntity.setZt("1");
        if(params.get("dwlx") != null){
            parExamPlanEntity.setDwlx(params.get("dwlx").toString());
        }
        if("1".equals(params.get("type"))){
            return parExamPlanBiz.selectList(parExamPlanEntity).stream().filter(item -> item.getKpr() == null).collect(Collectors.toList());
        }else{
            parExamPlanEntity.setKpr(params.get("deptCode").toString());
            return parExamPlanBiz.selectList(parExamPlanEntity);
        }

    }

    @RequestMapping(value = "/getAllOrg" ,method = RequestMethod.GET)
    public List<Map> getAllOrg(){
        return parExamInfoBiz.getAllOrg();
    }

    /**
     * @param  list 参数列表
     * @return 结果集
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public ObjectRestResponse<ParExamInfoEntity> add(@RequestBody List<ParExamInfoEntity> list) {
        if(list != null){
            for(ParExamInfoEntity parExamInfoEntity:list){
                //添加空字段默认值
                String id = UUIDUtils.generateShortUuid();
                parExamInfoEntity.setId(id);
                parExamInfoEntity.setScbj("0");
                baseBiz.add(parExamInfoEntity);
            }
        }
        return new ObjectRestResponse<ParExamInfoEntity>().rel(true);
    }

    @RequestMapping(value = "/getWorkInfo", method = RequestMethod.GET)
    public TableResultResponse<ParExamInfoEntity> getWorkInfo(@RequestParam Map<String, Object> params){
        Query query = new Query(params);
        return parExamInfoBiz.getWorkInfo(query);
    }

    @RequestMapping(value = "/getCate", method = RequestMethod.GET)
    public TableResultResponse<ParExamCateVO> getCate(@RequestParam Map<String, Object> params){
        Query query = new Query(params);
        return parExamInfoBiz.getCate(query);
    }

    @RequestMapping(value = "/addScore", method = RequestMethod.POST)
    @ResponseBody
    public ObjectRestResponse<ParExamScoreEntity> addScore(@RequestBody List<ParExamScoreEntity> list) {
        baseBiz.addScore(list);
        return new ObjectRestResponse<ParExamInfoEntity>().rel(true);
    }

    @RequestMapping(value = "/getScore" ,method = RequestMethod.GET)
    public List<ParExamScoreEntity> getScore(@RequestParam Map<String, Object> param){
        return parExamInfoBiz.getScore(param);
    }

    @RequestMapping(value = "/personPage", method = RequestMethod.GET)
    public TableResultResponse<ParExamInfoVO> personPage(@RequestParam Map<String, Object> params){
        params.put("crtUser",String.valueOf(request.getHeader(CommonConstants.WEB_USERID)));
        params.put("orgCode",String.valueOf(request.getHeader("orgCode")));
        Query query = new Query(params);
        return parExamInfoBiz.personPage(query);
    }

    @RequestMapping(value = "/getUserByOrgCode", method = RequestMethod.GET)
    public List<Map> getUserByOrgCode(@RequestParam Map<String, Object> params){
        return parExamInfoBiz.getUserByOrgCode(params.get("orgCode").toString());
    }
}
